package cn.com.jinhao.provider.user.controller;

import cn.com.jinhao.hotline.commons.controller.BaseController;
import cn.com.jinhao.hotline.commons.util.RestResponse;
import cn.com.jinhao.provider.user.entity.SysMenu;
import cn.com.jinhao.provider.user.service.MenuService;
import cn.com.jinhao.provider.user.vo.MenuRequestVO;
import cn.com.jinhao.provider.user.vo.MenuSRequestVo;
import cn.com.jinhao.provider.user.vo.MenuURequestVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * HotLine
 * <p>Description: 部门接口 </p>
 *
 * @author ShaneMew
 * @version 1.0
 * @date 2019/11/25
 * @since 2019-11-25
 */
@RestController
@RequestMapping("menus")
@Api(tags = {"路由信息服务"})
public class MenuController extends BaseController {
    @Resource
    private MenuService menuService;

    @ApiOperation(value = "新增路由", notes = "新增路由信息")
    @PostMapping
    public RestResponse<String> add(@ApiParam(name = "menuRequestVO", value = "路由信息", required = true) @Valid @RequestBody MenuRequestVO menuRequestVO, BindingResult result) throws Exception {
        validate(result);
        menuService.add(menuRequestVO);
        return new RestResponse<>(null);
    }

    @ApiOperation(value = "删除路由", notes = "根据路由编码删除路由信息")
    @DeleteMapping
    public RestResponse<String> deleteMenu(@ApiParam(name = "id", value = "路由唯一ID", required = true) @RequestParam String id) throws Exception {
        menuService.deleteById(id);
        return new RestResponse<>(null);
    }

    @ApiOperation(value = "更新路由", notes = "根据路由ID更新路由信息")
    @PutMapping
    public RestResponse<String> updateMenu(@ApiParam(value="路由信息", required = true) @Valid @RequestBody MenuURequestVO menuURequestVO, BindingResult result) throws Exception {
        validate(result);
        menuService.updateById(menuURequestVO);
        return new RestResponse<>(null);
    }

    @ApiOperation(value = "查询路由", notes = "通过角色查询路由信息")
    @PostMapping(value = "/selectByRoles")
    public RestResponse<java.util.List<SysMenu>> selectByRole(@ApiParam(name = "roles", value="角色列表", required = true) @Valid @RequestBody MenuSRequestVo roles, BindingResult result) throws Exception {
        validate(result);
        return new RestResponse<>(menuService.selectByRoles(roles));
    }
}
